import java.util.*;

public class TestDemo {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("hello",3);
        map.put("world",5);
        System.out.println(map);

        Set<String> set = map.keySet();
        System.out.println(set);

        Collection collection = map.values();
        System.out.println(collection);

        System.out.println("-----------------------------");

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> entry : entrySet ){
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
        System.out.println("-----------------------------");

        Set<Map.Entry<String,Integer>> entrySet1 = map.entrySet();
        Iterator<Map.Entry<String,Integer>> it = entrySet1.iterator();
        while(it.hasNext()){
            Map.Entry<String,Integer> entry = it.next();
            System.out.println(entry.getKey() + " " + entry.getValue());
        }

    }
    public static void main1(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("hello",3);
        map.put("world",5);
        //map.put(null,null);   // TreeMap不能存放null
        System.out.println(map);

        System.out.println("----------------------------------");

        int val = map.get("hello");
        System.out.println("val = " + val);

        Integer val1 = map.get("aaa");
        System.out.println(val1);
        Integer val2 = map.getOrDefault("aaa",666);
        System.out.println(val2);

        System.out.println("----------------------------------");

        Integer val3 = map.remove("hello");
        System.out.println(val3);
        System.out.println(map);
    }
}
